//
//  NetWorkRequestModel.h
//  singleTarget
//
//  Created by   李小云 on 17/9/20.
//  Copyright © 2017年   李小云. All rights reserved.
//

#import <Foundation/Foundation.h>

typedef NS_ENUM(NSInteger, NetWorkRequestType) {
     NetWorkRequestGet = 0, //get
     NetWorkRequestPost, //post
     NetWorkRequestUpLoad, //upload
     NetWorkRequestDownLoad,//Download
     NetWorkRequestResumeDownLoad //断点下载
};

typedef NS_ENUM(NSInteger, NetWorkCachesType) {
    CachesNone =0, //无需缓存
    CachesOnlyLocal,//只取缓存
    CachesOnlyRemoteButCaches,//取网络数据并缓存
    CachesFirstLocalAndRemote,//先本地在缓存 响应两次
    CachesFirstLocalOrRemote//有本地先取本地 没有在取网络数据
};

//网络请求成功的block
typedef void(^NetWorkSuccessRequest)(NSURLSessionDataTask *task, id resposeObject);
typedef void(^NetWorkFailRequest)(NSURLSessionDataTask *task, NSError *error);
typedef void(^NetWorkCachesRequest)(id cachesObject);
@interface NetWorkRequestModel : NSObject

/** 网络请求成功的block*/
@property(nonatomic,copy)NetWorkSuccessRequest successRequestBlock;
/** 网络请求失败的block*/
@property(nonatomic,copy)NetWorkFailRequest FailRequestBlock;
/** 网络请求缓存的block*/
@property(nonatomic,copy)NetWorkCachesRequest cachesBlock;

/** 网络请求方式*/
@property(nonatomic,assign)NetWorkRequestType requestType;

/** 网络缓存方式*/
@property(nonatomic,assign)NetWorkCachesType CachesType;

/** 请求url*/
@property(nonatomic,copy)NSString *url;
/** 请求参数*/
@property(nonatomic,copy)NSDictionary *parms;
/** 请求头参数*/
@property(nonatomic,copy)NSDictionary *headParms;
/** 请求参数是否JSON默认YES*/
@property(nonatomic,assign)BOOL isJsonRequetFormat;
/** 请求数据是否NSDATA默认NO*/
@property(nonatomic,assign)BOOL isNSDataReponseFormat;



//upLoad
/** 文件数据*/
@property(nonatomic,strong)NSData *fileData;
/** 文件参数名  服务端定义的*/
@property(nonatomic,strong)NSString *dataName;
/** 文件名称*/
@property(nonatomic,strong)NSString *fileName;
/** 文件类型*/
@property(nonatomic,strong)NSString *mimeType;
/**
 *  初始化请求模型
 *
 *  @param method       请求方式,字符串如@"get" , @"post"
 *  @param url          请求url
 *  @param parms        请求模型参数,传字典
 *  @param successBlock 成功的回调
 *  @param failBlock    失败的回调
 *
 *  @return NetWorkRequestModel 模型对象
 */
-(instancetype)initWithMethod:(NSString *)method
                          url:(NSString *)url
                        parms:(NSDictionary *)parms
                 successBlock:(NetWorkSuccessRequest)successBlock
                    failBlock:(NetWorkFailRequest)failBlock;


/**
 *  初始化请求模型
 *
 *  @param method       请求方式,字符串如@"get" , @"post"
 *  @param url          请求url
 *  @param parms        请求模型参数,传字典
 *  @param cachesType   缓存方式
 *  @param cachesBlock  缓存的回调
 *  @param successBlock 成功的回调
 *  @param failBlock    失败的回调
 *
 *  @return NetWorkRequestModel 模型对象
 */
-(instancetype)initWithMethod:(NSString *)method
                          url:(NSString *)url
                        parms:(NSDictionary *)parms
                   cachesType:(NetWorkCachesType)type
                  cachesBlock:(NetWorkCachesRequest)cachesBlock
                 successBlock:(NetWorkSuccessRequest)successBlock
                    failBlock:(NetWorkFailRequest)failBlock;


@end
